home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / feel0_89.lha / Feel / Src / system.c < prev    next >
C/C++ Source or Header  |  1993-07-01  |  16KB  |  810 lines

  1. /* ******************************************************************** */
  2. /* system.c          Copyright (C) Codemist and University of Bath 1989 */
  3. /*                                                                      */
  4. /* Environment specific code                                           */
  5. /* ******************************************************************** */
  6.  
  7. /*
  8.  * $Id: system.c,v 2.1 93/01/17 17:59:26 pab Exp $
  9.  *
  10.  * $Log:    system.c,v $
  11.  * Revision 2.1  93/01/17  17:59:26  pab
  12.  * New Version.
  13.  * Just Norcroft changes..
  14.  * 
  15.  * Revision 1.9  1992/11/26  16:09:59  pab
  16.  * More changes
  17.  *
  18.  * Revision 1.7  1992/06/16  19:32:16  pab
  19.  * MS-dross fixes
  20.  *
  21.  * Revision 1.6  1992/04/27  22:00:12  pab
  22.  * more volatile
  23.  *
  24.  * Revision 1.5  1992/04/26  21:09:45  pab
  25.  * added i860 support (needs checking)
  26.  *
  27.  * Revision 1.4  1992/02/10  12:01:10  pab
  28.  * Gc on/off fixes
  29.  *
  30.  * Revision 1.3  1992/01/29  13:49:07  pab
  31.  * sysV fixes
  32.  *
  33.  * Revision 1.2  1991/09/11  12:07:46  pab
  34.  * 11/9/91 First Alpha release of modified system
  35.  *
  36.  * Revision 1.1  1991/08/12  16:50:06  pab
  37.  * Initial revision
  38.  *
  39.  * Revision 1.9  1991/05/16  11:29:26  pab
  40.  * 'C' garbage collector additions
  41.  *
  42.  * Revision 1.8  1991/05/15  20:09:53  kjp
  43.  * Tidied suignal handling.
  44.  *
  45.  * Revision 1.7  1991/04/02  16:42:03  kjp
  46.  * BSD signal support.
  47.  *
  48.  * Revision 1.6  1991/02/28  13:53:54  kjp
  49.  * Fixed semaphore interaction with GC and sysv signalling.
  50.  *
  51.  * Revision 1.5  1991/02/13  18:25:46  kjp
  52.  * Pass.
  53.  *
  54.  */
  55.  
  56. #define SCHEDBUG(x) 
  57.  
  58. /*
  59.  * Change Log:
  60.  *   Version 1, April 1990
  61.  */
  62.  
  63. /*
  64.  
  65.  * This file (and it's accompanying '.h') are intended to encapsulate all
  66.  * of the system specific requirements of FEEL. For each target system
  67.  * there must be a set of functions conforming to the requested 
  68.  * configuration (e.g. if threads are required, the thread operations
  69.  * must exist along with their defined types - otherwise, they may be
  70.  * omitted).
  71.  
  72.  * It is expected that this file may degenerate into hash-includes.
  73.  
  74.  */
  75.  
  76. #include <signal.h>
  77.  
  78. #include "funcalls.h"
  79. #include "defs.h"
  80. #include "structs.h"
  81. #include "global.h"
  82. #include "error.h"
  83. #include "state.h"
  84.  
  85. #include "allocate.h"
  86. #include "garbage.h"
  87. #include "threads.h"
  88.  
  89.  
  90. #ifdef NORCROFT
  91. #include "/opt/home/jpff/Norcroft/syscall.h"
  92.  
  93. int fileno(FILE *f)
  94. {
  95.   return _fileno(f);
  96. }
  97.  
  98. int read(int fildes, void *buf, int nbyte)
  99. {
  100.   return _syscall3(SYS_read, fildes, buf, nbyte);
  101. }
  102.  
  103. int write(int fildes, void *buf, int nbyte)
  104. {
  105.   return _syscall3(SYS_write, fildes, buf, nbyte);
  106. }
  107.  
  108. int getpid(void)
  109. {
  110.   return _syscall0(SYS_getpid);
  111. }
  112.  
  113. int fork(void)
  114. {
  115.   return _vfork();
  116. }
  117.  
  118. #endif
  119.  
  120. /*
  121.  * Nasty signal hackery! 
  122.  */
  123.  
  124. #ifdef WITH_BSD_SIGNALS
  125. #define sighold(sig) sigmask(sig)
  126. #define sigset(sig,func) signal(sig,func)
  127. #define my_sigpause(sig) sigpause(0)
  128. #else
  129. #define my_sigpause(sig) sigpause(sig)
  130. #endif
  131.  
  132. /*
  133.  * For a system to run with threads, the following must be provided:
  134.  *
  135.  *   Types: 
  136.  *     SystemSemaphore 
  137.  *
  138.  *   Functions:
  139.  *
  140.  *     char* system_malloc(int)
  141.  *     char* system_static_malloc(int)
  142.  *
  143.  *     void system_allocate_semaphore(SystemSemaphore *)
  144.  *     void system_initialise_semaphore(SystemSemaphore *)
  145.  *     void system_open_semaphore(SystemSemaphore *)
  146.  *     void system_close_semaphore(SystemSemaphore *)
  147.  *
  148.  */
  149.  
  150. SYSTEM_THREAD_SPECIFIC_DECLARATION(int,system_scheduler_number);
  151.  
  152. int system_running_processors = 1; /* Unless initialised otherwise */
  153.  
  154. /*
  155.  * Stack checking...
  156.  */
  157.  
  158.  
  159. SYSTEM_GLOBAL(int,system_interrupt_flag);
  160.  
  161. /* C-c, and others interrupt handler... */
  162.  
  163. void system_handle_interrupts(LispObject *stacktop, int sig)
  164. {
  165.   int flags;
  166.  
  167.   flags=SYSTEM_GLOBAL_VALUE(system_interrupt_flag);
  168.   SYSTEM_GLOBAL_VALUE(system_interrupt_flag)=0;
  169.   
  170.   call_thread_signal(stacktop,CAR(interpreter_thread),flags);
  171. }
  172.  
  173. static void system_control_catcher(int sig)
  174. {
  175.   if (GOT_SIGNAL(SYSTEM_GLOBAL_VALUE(system_interrupt_flag),sig)) {
  176.     fprintf(stderr,"Go away and leave me alone!\n");
  177.     fflush(stderr);
  178.     sigset(sig,system_control_catcher); /* Reinstall */
  179.     return;
  180.   }
  181.   else
  182.     {
  183.       REGISTER_SIGNAL(SYSTEM_GLOBAL_VALUE(system_interrupt_flag),sig);
  184.       sigset(sig,system_control_catcher); /* Reinstall */
  185.     }
  186. }
  187.  
  188.  
  189. /* ******************************************************************** */
  190. /*                            Any Machine                               */
  191. /* ******************************************************************** */
  192.  
  193. #ifdef MACHINE_ANY
  194. #ifndef CGC
  195. char *system_malloc(int n)
  196. {
  197.   char *sbrk(int);
  198.   char *addr;
  199.  
  200.   if ((addr = (char *) sbrk(n)) == (char *) -1) {
  201.     perror("INITERROR: unable to allocate enough memory from system\n");
  202.     system_lisp_exit(1);
  203.   }
  204.  
  205.   return(addr);
  206. }
  207.  
  208. char *system_static_malloc(int n)
  209. {
  210.   char *sbrk(int);
  211.   char *addr;
  212.  
  213.   if ((addr = (char *) sbrk(n)) == (char *) -1) {
  214.     perror("INITERROR: out of static memory\n");
  215.     system_lisp_exit(1);
  216.   }
  217.  
  218.   return(addr);
  219. }
  220. #endif
  221. void system_lisp_exit(int n) 
  222. {
  223.   exit(n);
  224. }
  225.  
  226. void system_abort(int sig)
  227. {
  228.   fprintf(stderr,"\n\nAborting feel on signal %d\n\n",sig);
  229.   exit(sig);
  230. }
  231.  
  232. void runtime_initialise_system() 
  233. {
  234.   system_scheduler_number = 0;
  235.  
  236. #ifdef CGC
  237.   gc_init();
  238. #endif
  239.  
  240. #ifdef TRAP_ALL
  241.   signal(15,system_abort); 
  242.   signal(11,system_abort);
  243.   signal(10,system_abort);
  244.   signal(02,system_control_catcher); 
  245. #endif
  246.  
  247.   SYSTEM_INITIALISE_GLOBAL(int,system_interrupt_flag,FALSE);
  248. }
  249.  
  250. #endif
  251.  
  252. /* ******************************************************************** */
  253. /*                               BSD                                    */
  254. /* ******************************************************************** */
  255.  
  256. #ifdef MACHINE_BSD
  257.  
  258. /*
  259.  * Memory allocation... 
  260.  */
  261.  
  262. char *system_malloc(int n)
  263. {
  264.   char *sbrk(int);
  265.   char *addr;
  266.  
  267.   if ((addr = (char *) sbrk(n)) == (char *) -1) {
  268.     perror("INITERROR: unable to allocate enough memory from system\n");
  269.     system_lisp_exit(1);
  270.   }
  271.  
  272.   return(addr);
  273. }
  274.  
  275. #define STATIC_MALLOC_HUNK_SIZE (4096)
  276.  
  277. char *static_free_ptr;
  278. int static_free_count;
  279.  
  280. char *system_static_malloc(int n)
  281. {
  282.   char *val;
  283.  
  284.   n = n + (n%BYTE_ALIGNMENT == 0 ? n : (BYTE_ALIGNMENT-n%BYTE_ALIGNMENT)); 
  285.   /* Alignment.. */
  286.  
  287.   if (static_free_count < n) {
  288.     char *new;
  289.  
  290.     if ((new = system_malloc(STATIC_MALLOC_HUNK_SIZE)) == NULL) {
  291.       fprintf(stderr,"INIT ERR: out of static memory\n");
  292.       exit(1);
  293.     }
  294.  
  295.     static_free_ptr = new;
  296.     static_free_count = STATIC_MALLOC_HUNK_SIZE;
  297.   }
  298.  
  299.   val = static_free_ptr;
  300.   static_free_ptr = val + n;
  301.   static_free_count -= n;
  302.  
  303.   return(val);
  304. }
  305.  
  306. /*
  307.  * Semaphores... (in header - dummies)
  308.  */
  309.  
  310. /*
  311.  * Signal handling...
  312.  */
  313.  
  314. /* Bad news signal handler... */
  315.  
  316. void system_abort(int sig)
  317. {
  318.   fprintf(stderr,"\n\nAborting EuLisp on signal %d... ",sig);
  319.   fprintf(stderr,"done\n\n");
  320.  
  321.   exit(1);
  322. }
  323.  
  324. /*
  325.  * Init and cleanup... 
  326.  */
  327.  
  328. void system_lisp_exit(int n)
  329. {
  330.   exit(n);
  331. }
  332.  
  333. void system_sleep_until_kicked() {}
  334.  
  335. void system_kick_sleepers() {}
  336.  
  337. void system_register_process(int pid) {IGNORE(pid);}
  338.  
  339. void runtime_initialise_system() 
  340. {
  341.   signal(SIGTERM,system_abort); /* Catch terminations */
  342. /*
  343.   signal(SIGSEGV,system_abort);
  344.   signal(SIGBUS,system_abort);
  345. */
  346.   signal(SIGINT,system_control_catcher); /* C-c with any luck */
  347.   system_scheduler_number = 0;
  348. #ifdef CGC
  349.    gc_init();
  350. #endif
  351.  
  352.  
  353.   SYSTEM_INITIALISE_GLOBAL(int,system_interrupt_flag,FALSE);
  354. }
  355.  
  356. #endif
  357.  
  358. /* ******************************************************************** */
  359. /*                             System V                                 */
  360. /* ******************************************************************** */
  361.  
  362. #ifdef MACHINE_SYSTEMV
  363.  
  364. /*
  365.  * Memory allocation...
  366.  */
  367.  
  368. /* Of shared memory segments... */
  369.  
  370. #define MAX_SHARED_SEGMENTS 100
  371.  
  372. int shared_ids[MAX_SHARED_SEGMENTS];
  373. int shared_segment_count;
  374.  
  375. #if i860
  376. #include <errno.h>
  377. #define MAX_SHARED_PAGE_SZ 1024*1024
  378. #define PAGE_BOUNDARY 4096
  379.   char *system_malloc(int n)
  380.   {
  381.  char *alloc_memory_block(int size);
  382.  char *addr=0;
  383.  int k=0;
  384.  int left=n;
  385.  
  386.  if (n==0)
  387.    return NULL;
  388.  
  389.  while (left > MAX_SHARED_PAGE_SZ || addr==0)
  390.    {
  391.      if (addr==0)
  392.     addr=alloc_memory_block(MAX_SHARED_PAGE_SZ);
  393.      else 
  394.     alloc_memory_block(MAX_SHARED_PAGE_SZ);
  395.      left -=MAX_SHARED_PAGE_SZ;
  396.    }
  397.  if (left>0)
  398.    alloc_memory_block(left);
  399.  return addr;
  400. }
  401.  
  402. char *alloc_memory_block(int size)
  403. {
  404.  static int id=0;
  405.  char *addr;
  406.  int res;
  407.  
  408.  if (id==0)
  409.    id=25;
  410.  printf("alloc: %d %d\n",id,size);
  411.  
  412.  if (size==0)
  413.    return NULL;
  414.  
  415.  if ((size&(PAGE_BOUNDARY-1)))
  416.    size=(size+PAGE_BOUNDARY)&(~(PAGE_BOUNDARY-1));
  417.  
  418.  addr=sbrk(0);
  419.  if (((int)addr&(PAGE_BOUNDARY-1)))
  420.    addr= (char *)(((int)addr+PAGE_BOUNDARY)&(~(PAGE_BOUNDARY-1)));
  421.  
  422.  if (brk(addr+size)==-1)
  423.    perror("Brk");
  424.  printf("allocating: %x,%x\n",addr,size);
  425.  do
  426.    {
  427.      extern volatile int errno;
  428.      errno=0;
  429.      id++;
  430.      res=create_shared_region(id,addr,size,0);
  431.      if (res<0)
  432.     perror("create");
  433.    }
  434.  while (res==-1 && errno==EINVAL);
  435.  
  436.  if (res== -1)
  437.    perror("create");
  438.  shared_ids[shared_segment_count] = id;
  439.  
  440.  ++shared_segment_count;  
  441.  id++;
  442.  
  443.  return addr;
  444. }
  445.  
  446.  
  447. #else
  448. char *system_malloc(int n)
  449. {
  450.   int seg;
  451.   char *addr;
  452.  
  453.   if (shared_segment_count >= MAX_SHARED_SEGMENTS) {
  454.     fprintf(stderr,"Can't allocate shared segment\n");
  455.     system_lisp_exit(1);
  456.   }
  457.  
  458.   if ((seg = shmget(IPC_PRIVATE,n,511|IPC_CREAT)) < 0) {
  459.     perror("shmget\n");
  460.     system_lisp_exit(1);
  461.   }
  462.  
  463.   if ((int) (addr = shmat(seg,NULL,NULL)) == -1) {
  464.     perror("shmat\n");
  465.     system_lisp_exit(1);
  466.   }
  467.  
  468.   shared_ids[shared_segment_count] = seg;
  469.  
  470.   ++shared_segment_count;
  471.  
  472.   return(addr);
  473. }
  474. #endif
  475. /* Of static shared bits (assumes serial for now)... */
  476.  
  477. #define STATIC_MALLOC_HUNK_SIZE (4096)
  478.  
  479. char *static_free_ptr;
  480. int static_free_count;
  481.  
  482. char *system_static_malloc(int n)
  483. {
  484.   char *val;
  485.  
  486.   n = n + (n%BYTE_ALIGNMENT == 0 ? n : (BYTE_ALIGNMENT-n%BYTE_ALIGNMENT)); 
  487.   /* Alignment.. */
  488.  
  489.   if (static_free_count < n) {
  490.     char *new;
  491.  
  492.     if ((new = system_malloc(STATIC_MALLOC_HUNK_SIZE)) == NULL) {
  493.       fprintf(stderr,"INIT ERR: out of static memory\n");
  494.       system_lisp_exit(1);
  495.     }
  496.  
  497.     static_free_ptr = new;
  498.     static_free_count = STATIC_MALLOC_HUNK_SIZE;
  499.   }
  500.  
  501.   val = static_free_ptr;
  502.   static_free_ptr = val + n;
  503.   static_free_count -= n;
  504.  
  505.   return(val);
  506. }
  507.  
  508. /*
  509.  * Semaphores...
  510.  */
  511.  
  512. void system_initialise_semaphore(SystemSemaphore *ptr)
  513. {
  514.   *ptr = 1;
  515. }
  516.  
  517. void system_allocate_semaphore(SystemSemaphore *ptr)
  518. {
  519.   *ptr = 1;
  520. }
  521. /* SystemV Semaphores excluded */
  522.  
  523. #ifdef SEMAPHORES_SOFTWARE
  524.  
  525. #include "lamport.h"
  526.  
  527. LamportSemaphore system_semaphore;
  528.  
  529. void system_open_semaphore(LispObject *stacktop, SystemSemaphore *ptr)
  530. {
  531.   extern SYSTEM_GLOBAL(SystemSemaphore,GC_sem);
  532.   int mine_flag = FALSE;
  533.  
  534.  top:
  535.  
  536.   lamport_enter(system_semaphore,system_scheduler_number);
  537.  
  538.   if (*ptr == 1) {
  539.     *ptr = 0;
  540.     mine_flag = TRUE;
  541.   }
  542.  
  543.   lamport_exit(system_semaphore,system_scheduler_number);
  544.  
  545.   if (mine_flag) return;
  546.  
  547.   if (ptr != &SYSTEM_GLOBAL_VALUE(GC_sem))
  548.     while (*(volatile SystemSemaphore *)ptr != 1) GC_sync_test();
  549.   else
  550.     while (*(volatile SystemSemaphore *)ptr != 1);
  551.  
  552.   goto top;
  553. }
  554.  
  555. #ifdef RETRY_OPEN_SEM
  556. int system_maybe_open_semaphore(LispObject *stacktop, SystemSemaphore *ptr)
  557. {
  558.   int mine_flag = FALSE;
  559.   int i=0;
  560.  
  561.   for (i=0 ; i<RETRY_OPEN_SEM ; i++)
  562.     {
  563.       lamport_enter(system_semaphore,system_scheduler_number);
  564.  
  565.       if (*ptr == 1) {
  566.     *ptr = 0;
  567.     mine_flag = TRUE;
  568.     break;
  569.       }
  570.       lamport_exit(system_semaphore,system_scheduler_number);
  571.     }
  572.   GC_sync_test();
  573.  
  574.   return(mine_flag);
  575. }
  576.  
  577. #else
  578. int system_maybe_open_semaphore(LispObject *stacktop, SystemSemaphore *ptr)
  579. {
  580.   int mine_flag = FALSE;
  581.  
  582.   lamport_enter(system_semaphore,system_scheduler_number);
  583.  
  584.   if (*ptr == 1) {
  585.     *ptr = 0;
  586.     mine_flag = TRUE;
  587.   }
  588.  
  589.   lamport_exit(system_semaphore,system_scheduler_number);
  590.  
  591.   GC_sync_test();
  592.  
  593.   return(mine_flag);
  594. }
  595. #endif
  596. #endif
  597.  
  598. void system_close_semaphore(SystemSemaphore *ptr)
  599. {
  600.   *ptr = 1;
  601. }
  602.  
  603. /*
  604.  * Signal handling...
  605.  */
  606.  
  607. static SYSTEM_GLOBAL_ARRAY1(int,system_pids,MAX_PROCESSORS);
  608.  
  609. /* Bad news, free up semaphores and shared memory... */
  610.  
  611. void system_abort(int sig)
  612. {
  613.   int i;
  614.  
  615.   fprintf(stderr,"\n\nAborting EuLisp on signal %d... ",sig);
  616.  
  617.   for (i=0;i<shared_segment_count;++i) {
  618.     (void) shmctl(shared_ids[i],IPC_RMID,NULL);
  619.   }
  620.  
  621.  
  622. #if i860
  623.   for (i=0; i<shared_segment_count ; i++)
  624.     delete_shared_region(shared_ids[i]);
  625. #else
  626.     for (i=0;i<shared_segment_count;++i) {
  627.       (void) shmctl(shared_ids[i],IPC_RMID,NULL);
  628.     }
  629. #endif
  630.   /* Kill of other processes too */
  631.  
  632.   for (i=0; i<RUNNING_PROCESSORS(); ++i)
  633.     if (i != system_scheduler_number)
  634.       kill(SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,i),SIGQUIT);
  635.  
  636.   fprintf(stderr,"done\n\n");
  637.  
  638.   exit(1);
  639. }
  640.  
  641. /*
  642.  * Init and cleanup... 
  643.  */
  644.  
  645. void system_lisp_exit(int n)
  646. {
  647.   int i;
  648.  
  649.   for (i=0;i<shared_segment_count;++i) {
  650.     (void) shmctl(shared_ids[i],IPC_RMID,NULL);
  651.   }
  652.  
  653.   (void) semctl(system_semaphore,NULL,IPC_RMID,NULL);
  654.  
  655.   /* Kill of other processes too */
  656.  
  657.   for (i=0; i<RUNNING_PROCESSORS(); ++i)
  658.     if (i != system_scheduler_number)
  659.       kill(SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,i),SIGQUIT);
  660.  
  661.   exit(n);
  662. }
  663.  
  664. /*
  665.  * Signal fiddling...
  666.  */
  667.  
  668. #define KICK_SIGNAL (SIGUSR1)
  669.  
  670. void system_kick_pid(int pid)
  671. {
  672.   extern int kill(int,int);
  673.  
  674.   (void) kill(pid,KICK_SIGNAL);
  675. }
  676.  
  677. static void system_nout()
  678. {
  679.   sigset(KICK_SIGNAL,system_nout);
  680. }
  681.  
  682. void system_sleep_until_kicked()
  683. {
  684.   extern int sigpause(int);
  685.  
  686.   (void) my_sigpause(KICK_SIGNAL);
  687.   sighold(KICK_SIGNAL);
  688. /*
  689.   fprintf(stderr,"{W:%d}\n",system_scheduler_number); fflush(stderr);
  690. */
  691.   fflush(stderr);
  692. }
  693.  
  694. static void system_read_nout()
  695. {
  696.   sigset(KICK_SIGNAL,system_read_nout);
  697. /*  GC_sync_test();*/
  698. }
  699.  
  700. #include <errno.h>
  701.  
  702. int system_read(int fno,char *buf,int max)
  703. {
  704.   int error;
  705.  
  706.   (void) sigset(KICK_SIGNAL,system_read_nout);
  707.  
  708.   do {
  709.  
  710.     error = read(fno,buf,max);
  711.     if (error > 0) {
  712.  
  713.       sigset(KICK_SIGNAL,system_nout);
  714.       (void) sighold(KICK_SIGNAL);
  715.  
  716. #ifndef i860
  717.       PROFILE(printf("PVAL:%x\n",PROFILE_TIME(system_local_timer)));
  718. #endif
  719.       fflush(stdout);
  720.       return(error);
  721.     }
  722.  
  723.   } while (errno == EINTR);
  724.  
  725.   return(error);
  726. }
  727.  
  728. void system_kick_sleepers()
  729. {
  730.   int i;
  731.  
  732.   for (i=0; i<RUNNING_PROCESSORS(); ++i)
  733.     if (i != system_scheduler_number)
  734.       kill(SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,i),KICK_SIGNAL);
  735. }
  736.  
  737. #ifndef i860
  738. DEF_PROFILE_TIMER(system_local_timer);
  739. #endif
  740.  
  741. void system_register_process(int n)
  742. {
  743.   SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,n) = getpid();
  744.   sigset(KICK_SIGNAL,system_nout);
  745.   sighold(KICK_SIGNAL);
  746.  
  747. #ifdef i860
  748.   INIT_PROFILE_TIMER(system_local_timer);
  749. #endif
  750. }
  751.  
  752. SYSTEM_GLOBAL(SystemSemaphore, atomic_semaphore);
  753.  
  754. void runtime_initialise_system()
  755. {
  756.  
  757. #ifdef SEMAPHORES_SYSTEMV
  758.  
  759.   if ((system_semaphore = semget(IPC_PRIVATE,1,511)) < 0) {
  760.     perror("INIT ERROR: can't get semaphore\n");
  761.     exit(1);
  762.   }
  763.   if (semctl(system_semaphore,0,SETVAL,1) < 0) {
  764.     perror("INIT ERROR: initialise semaphore\n");
  765.     exit(1);
  766.   }
  767.  
  768.   system_sem_handler_array[0][0].sem_num = 0;
  769.   system_sem_handler_array[0][0].sem_op = -1;
  770.   system_sem_handler_array[0][0].sem_flg = NULL;
  771.  
  772. #endif
  773.   shared_segment_count = 0;
  774.  
  775.   static_free_ptr = NULL;
  776.   static_free_count = 0;
  777.  
  778.   /* Bad news signals */
  779.  
  780.   sigset(SIGTERM,system_abort); /* Catch terminations */
  781.   sigset(SIGQUIT,system_abort); /* Quits */
  782.   sigset(SIGSEGV,system_abort); /* Segmentation faults */
  783.   sigset(SIGBUS,system_abort);  /* Bus errors */
  784.   /* Error trapped signals */
  785.  
  786.   sigset(SIGINT,system_control_catcher); /* C-c with any luck */
  787.  
  788.   /* Ignore kick signals until we need them */
  789.  
  790.   sighold(KICK_SIGNAL); 
  791.  
  792. #ifdef SEMAPHORES_SOFTWARE
  793.  
  794.   system_semaphore 
  795.     = (LamportSemaphore) 
  796.         system_static_malloc(sizeof(struct lamport_semaphore));
  797.   lamport_initialise(system_semaphore);
  798.  
  799.   SYSTEM_INITIALISE_GLOBAL_ARRAY1(int,system_pids,MAX_PROCESSORS,0);
  800.   SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,0) = getpid();
  801. #endif
  802.  
  803.   SYSTEM_INITIALISE_GLOBAL(SystemSemaphore, atomic_semaphore, NULL);
  804.   system_allocate_semaphore(&SYSTEM_GLOBAL_VALUE(atomic_semaphore));
  805.   SYSTEM_INITIALISE_GLOBAL(int,system_interrupt_flag,FALSE);
  806. }
  807.  
  808. #endif
  809.  
  810.